package leetcode.greed;

/**
 * @author mazouri
 * @create 2021-12-27 19:02
 */
public class _45_jump {
    public int jump(int[] nums) {
        int start = 0;
        int end = 1;
        int count = 0;

        while (end < nums.length) {
            int max = 0;
            for (int i = start; i < end; i++) {
                // 能跳到最远的距离
                max = Math.max(max, i + nums[i]);
            }

            // 下一次起跳点范围开始的格子
            start = end;
            // 下一次起跳点范围结束的格子
            end = max + 1;
            //跳跃次数
            count++;
        }
        return count;
    }
}
